{ "cells": [ { "cell_type": "markdown", "id": "ad441e7b", "metadata": {}, "source": [ "# Overriding a Mechanism in MusicBox\n", "\n", "The MusicBox class only supports one mechanism at a time. If you desire to change the mechanism within the class, you will need to override it from scratch." ] }, { "cell_type": "markdown", "id": "cad0ad50", "metadata": {}, "source": [ "## 1. Creating the Mechanism and Box Model\n", "\n", "This is simply a copy of the first half of the [Basic Workflow Tutorial](1.%20basic_workflow.ipynb) to set up the mechanism for overriding." ] }, { "cell_type": "code", "execution_count": 1, "id": "f0cb3f6f", "metadata": {}, "outputs": [], "source": [ "from acom_music_box import MusicBox, Conditions\n", "import musica.mechanism_configuration as mc\n", "import matplotlib.pyplot as plt\n", "\n", "# Create each of the species that will be simulated\n", "X = mc.Species(name=\"X\")\n", "Y = mc.Species(name=\"Y\")\n", "Z = mc.Species(name=\"Z\")\n", "species = {\"X\": X, \"Y\": Y, \"Z\": Z}\n", "gas = mc.Phase(name=\"gas\", species=list(species.values()))\n", "# Create the reactions that the species undergo in the\n", "arr1 = mc.Arrhenius(name=\"X->Y\", A=4.0e-3, C=50, reactants=[species[\"X\"]], products=[species[\"Y\"]], gas_phase=gas)\n", "arr2 = mc.Arrhenius(name=\"Y->Z\", A=4.0e-3, C=50, reactants=[species[\"Y\"]], products=[species[\"Z\"]], gas_phase=gas)\n", "rxns = {\"X->Y\": arr1, \"Y->Z\": arr2}\n", "# Create the mechanism that is defined by the species, phases, and reactions\n", "mechanism = mc.Mechanism(name=\"tutorial_mechanism\", species=list(species.values()), phases=[gas], reactions=list(rxns.values()))\n", "# Create the box model that contains the mechanism\n", "box_model = MusicBox()\n", "box_model.load_mechanism(mechanism)" ] }, { "cell_type": "markdown", "id": "017f8fa1", "metadata": {}, "source": [ "## 2. Redefining Code\n", "\n", "For the sake of readability, the code from the previous cells will be redefined here to represent the new mechanism.\n", "Here, a new type of reaction is used, called a quantum tunneling reaction:" ] }, { "cell_type": "code", "execution_count": 2, "id": "6c840133", "metadata": {}, "outputs": [], "source": [ "# Create each of the species that will be simulated\n", "G = mc.Species(name=\"G\")\n", "H = mc.Species(name=\"H\")\n", "species = {\"G\": G, \"H\": H}\n", "gas = mc.Phase(name=\"gas\", species=list(species.values()))\n", "# Create the reactions that the species undergo in the\n", "arr1 = mc.Tunneling(name=\"G->H\", A=2.0e-3, B=2, C=50, reactants=[species[\"G\"]], products=[species[\"H\"]], gas_phase=gas)\n", "arr2 = mc.Tunneling(name=\"H->G\", A=9.0e-3, B=2, C=50, reactants=[species[\"H\"]], products=[species[\"G\"]], gas_phase=gas)\n", "rxns = {\"G->H\": arr1, \"H->G\": arr2}\n", "# Create the mechanism that is defined by the species, phases, and reactions\n", "mechanism = mc.Mechanism(name=\"overriden_mechanism\", species=list(species.values()), phases=[gas], reactions=list(rxns.values()))\n", "# Create the box model that contains the new mechanism\n", "box_model.load_mechanism(mechanism)" ] }, { "cell_type": "markdown", "id": "62878d04", "metadata": {}, "source": [ "## 3. Running and Visualizing the new Box Model\n", "\n", "The rest of this code is an adapted version of the Basic Workflow code to run with the new mechanism. Refer to there for explanations about the code:" ] }, { "cell_type": "code", "execution_count": 3, "id": "c2f1f497", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ " " ] }, { "name": "stderr", "output_type": "stream", "text": [ "\r" ] }, { "data": { "text/html": [ "
\n", " | time.s | \n", "ENV.temperature.K | \n", "ENV.pressure.Pa | \n", "ENV.air number density.mol m-3 | \n", "CONC.G.mol m-3 | \n", "CONC.H.mol m-3 | \n", "
---|---|---|---|---|---|---|
0 | \n", "0.0 | \n", "298.15 | \n", "101325.0 | \n", "40.874045 | \n", "2.500000 | \n", "5.000000 | \n", "
1 | \n", "20.0 | \n", "298.15 | \n", "101325.0 | \n", "40.874045 | \n", "3.213819 | \n", "4.286181 | \n", "
2 | \n", "40.0 | \n", "298.15 | \n", "101325.0 | \n", "40.874045 | \n", "3.787516 | \n", "3.712484 | \n", "
3 | \n", "60.0 | \n", "298.15 | \n", "101325.0 | \n", "40.874045 | \n", "4.248595 | \n", "3.251405 | \n", "
4 | \n", "80.0 | \n", "298.15 | \n", "101325.0 | \n", "40.874045 | \n", "4.619165 | \n", "2.880835 | \n", "
5 | \n", "100.0 | \n", "298.15 | \n", "101325.0 | \n", "40.874045 | \n", "4.916991 | \n", "2.583009 | \n", "
6 | \n", "120.0 | \n", "310.00 | \n", "100100.0 | \n", "38.836331 | \n", "5.156409 | \n", "2.343591 | \n", "
7 | \n", "140.0 | \n", "310.00 | \n", "100100.0 | \n", "38.836331 | \n", "5.348819 | \n", "2.151181 | \n", "
8 | \n", "160.0 | \n", "310.00 | \n", "100100.0 | \n", "38.836331 | \n", "5.503449 | \n", "1.996551 | \n", "
9 | \n", "180.0 | \n", "310.00 | \n", "100100.0 | \n", "38.836331 | \n", "5.627719 | \n", "1.872281 | \n", "
10 | \n", "200.0 | \n", "310.00 | \n", "100100.0 | \n", "38.836331 | \n", "5.727589 | \n", "1.772411 | \n", "